package com.zj.common;

import java.util.ArrayList;
import java.util.List;

import com.zj.common.req.BusinessContent;
import com.zj.common.req.Code;
import com.zj.common.req.ContentControl;
import com.zj.common.req.Encrypt;
import com.zj.common.req.Identity;
import com.zj.common.req.ParamList;
import com.zj.common.req.ReturnState;
import com.zj.common.req.SubPackage;
import com.zj.common.req.Zip;
import com.zj.common.xml.XmlUtil;
import com.zj.request.PkBody;
import com.zj.request.body.Jbyhxx;
import com.zj.request.body.Jsyhxx;
import com.zj.request.body.Spmx;
import com.zj.request.body.SpmxList;
import com.zj.request.body.Szmx;
import com.zj.request.body.SzmxList;
import com.zj.request.head.JhSyPkReqHead;
import com.zj.response.PkResBody;
import com.zj.response.body.ReturnInfo;
import com.zj.response.head.JhSyPkResHead;

public class Test {

	
	public static void main(String[] args) {
		pk();
	}
	// pk測試
	public static void pk() {
		PkBody open = new PkBody();
		JhSyPkReqHead head = new JhSyPkReqHead("11101020000", "102100009980", "20192012", "20181012", "23423421", 20,
				"580.2");
		open.setHead(head);
		Szmx szmx = new Szmx("201810", "201811", "58290", "税收收入", "307229070", "城市维护建设税", "0087492444858201", "城镇土地使用税",
				"566.2");
		Szmx szmx1 = new Szmx("201810", "201811", "58290", "税收收入", "307229070", "城市维护建设税", "0087492444858201",
				"城镇土地使用税", "566.2");
		List<SzmxList> list = new ArrayList<>();
		List<SzmxList> list1 = new ArrayList<>();
	
		list.add(new SzmxList(szmx));
		list.add(new SzmxList(szmx1));
		Spmx spmx = new Spmx("131029111111112209", "23423423", "110105774706306", "北京福宁乐超市", "11101020000",
				"北京市丰台区国家税务局", "46385039586239872398568346593875136902365290692339098568653",
				new Jbyhxx("9991", "402100000018", "农商行", "080100002451054", "080100002451054"),
				new Jsyhxx("9991", "402100000018", "农商行", "080100002451054"), "820.0", "20181122", list);
		Spmx spmx1 = new Spmx("131029111111112209", "23423423", "110105774706306", "北京福宁乐超市", "11101020000",
				"北京市丰台区国家税务局", "46385039586239872398568346593875136902365290692339098568653",
				new Jbyhxx("9991", "402100000018", "农商行", "080100002451054", "080100002451054"),
				new Jsyhxx("9991", "402100000018", "农商行", "080100002451054"), "820.0", "20181122", list1);
		List spmxlist = new ArrayList<>();
		SpmxList spList = new SpmxList(spmx);
		SpmxList splist2 = new SpmxList(spmx1);
		spmxlist.add(spList);
		spmxlist.add(splist2);
		open.setBody(spmxlist);
		String content = XmlUtil.toXmlNoHead(open);
		TiripPackage tiripPackage = new TiripPackage();
		Identity identity = new Identity("SYPKA1", "");
		tiripPackage.setIdentity(identity);
		ContentControl contentControl = new ContentControl();
		contentControl.setCode(new Code());
		contentControl.setEncrypt(new Encrypt());
		contentControl.setZip(new Zip());
		List<ParamList> listparam = new ArrayList<>();
		ParamList a = new ParamList("YH_APP", "105");
		ParamList b = new ParamList("tran_time", "20181119182314");
		listparam.add(a);
		listparam.add(b);
		tiripPackage.setRouterSession(listparam);
		tiripPackage.setContentControl(contentControl);
		ReturnState returnState = new ReturnState("00", "12");
		tiripPackage.setReturnState(returnState);
		SubPackage sub = new SubPackage(XmlUtil.addCdata(content));
		BusinessContent businessContent = new BusinessContent();
		businessContent.setSubPackage(sub);
		tiripPackage.setBusinessContent(businessContent);
		String str = XmlUtil.toXml(tiripPackage, "GBK");
		System.out.println(str);
		TiripPackage tri = XmlUtil.toBean(str, TiripPackage.class);
		System.out.println(XmlUtil.subCdata(tri));
		PkBody open1 = XmlUtil.toBean(XmlUtil.subCdata(tri), PkBody.class);
		System.out.println(open1);

		tiripPackage.getIdentity().setServiceId("SYPKA2");
		tiripPackage.setContentControl(new com.zj.common.req.ContentControl());
		tiripPackage.setReturnState(new ReturnState("000", "成功"));

	    com.zj.response.SpmxList res1 = new com.zj.response.SpmxList(new com.zj.response.body.Spmx("131029111111112209", "20701240", "820", "20180202", new ReturnInfo("000", "成功")));
		com.zj.response.SpmxList res12 = new com.zj.response.SpmxList(new com.zj.response.body.Spmx("131029111DS111112209", "20701SD240", "82DS0", "20SD180202", new ReturnInfo("000", "成功")));
		List<com.zj.response.SpmxList> ll11 =  new ArrayList<>();
		ll11.add(res12);
		ll11.add(res1);
		PkResBody openResp = new PkResBody(
				new JhSyPkResHead(head.getZsjgDm(), head.getYhdm(), head.getWtrq(), head.getRqrq(), head.getSwblsh()),
				ll11);
		openResp.setName("个人税务实扣缴费结果回执响应（对外）");
		openResp.setCnName("jhSySkResponse");
		tiripPackage.setBusinessContent(
				new BusinessContent(new SubPackage(XmlUtil.addCdata(XmlUtil.toXmlNoHead(openResp)))));
		System.out.println("测试输出"+ XmlUtil.toXml(tiripPackage, "GBK"));

	}
}
